---
title: Metrics exporters
subtitle: Export router metrics
description: Collect and export metrics from the Apollo GraphOS Router or Apollo Router Core for Prometheus, OpenTelemetry Protocol (OTLP), Datadog, and New Relic.
redirectFrom:
  - /technotes/TN0015-router-to-apm-via-opentelemetry/
  - /graphos/routing/observability/telemetry/metrics-exporters/overview
context:
  - telemetry
---

The GraphOS Router and Apollo Router Core support collection of metrics with [OpenTelemetry](https://opentelemetry.io/), with exporters for:

* [Prometheus](/router/configuration/telemetry/exporters/metrics/prometheus)
* [OpenTelemetry Protocol (OTLP)](/router/configuration/telemetry/exporters/metrics/otlp)
* [Datadog via OTLP](/router/configuration/telemetry/exporters/metrics/datadog)
* [New Relic via OTLP](/router/configuration/telemetry/exporters/metrics/new-relic)

In [`router.yaml`](/router/configuration/overview/#yaml-config-file), you configure router metrics with the following settings:

- `telemetry.exporters.metrics.common`. Configure values for the router which are common across metrics exporters.
- `telemetry.exporters.metrics.prometheus`. Configure the Prometheus exporter.
- `telemetry.exporters.metrics.otlp`. Configure the OpenTelemetry exporter. Supports sending traces to Datadog.

## Metrics common configuration

Common metrics configuration contains global settings for all exporters:

* [Service name](#service_name)
* [Resource attributes](#resource)
* [Custom default histogram buckets](#buckets)
* [OpenTelemetry views](#views)

### `service_name`

Set a service name for your router metrics so you can easily locate them in external metrics dashboards. 

The service name can be set by an environment variable or in [`router.yaml`](/router/configuration/overview/#yaml-config-file), with the following order of precedence (first to last):

1. `OTEL_SERVICE_NAME` environment variable
2. `OTEL_RESOURCE_ATTRIBUTES` environment variable
3. `telemetry.exporters.metrics.common.service_name` in `router.yaml`

      <ExpansionPanel title="Example service_name">

      Example setting service name in `telemetry.exporters.metrics.common.service_name`:

      ```yaml title="router.yaml"
      telemetry:
        exporters:
          metrics:
            common:
              # (Optional) Set the service name to easily find metrics related to the apollo-router in your metrics dashboards
              service_name: "router" #highlight-line
      ```

      </ExpansionPanel>


4. `telemetry.exporters.metrics.common.resource` in `router.yaml`

      <ExpansionPanel title="Example resource">

      Example setting service name in `telemetry.exporters.metrics.common.resource`:

      ```yaml title="router.yaml"
      telemetry:
        exporters:
          metrics:
            common:
              resource:
                # (Optional) Set the service name to easily find metrics related to the apollo-router in your metrics dashboards
                "service.name": "router" #highlight-line
      ```

      </ExpansionPanel>

If the service name isn't explicitly set, it defaults to `unknown_service:router` or `unknown_service` if the executable name cannot be determined.

### `resource`

A resource attribute is a set of key-value pairs that provide additional information to an exporter. It's an attribute of an [OpenTelemetry resource](https://opentelemetry.io/docs/specs/otel/resource/sdk/). Application performance monitors (APM) can interpret and display resource information. 

In [`router.yaml`](/router/configuration/overview/#yaml-config-file), resource attributes are set in `telemetry.metrics.common.resource`. For example:

```yaml title="router.yaml"
telemetry:
  exporters:
    metrics:
      common:
        resource:
          "deployment.environment.name": "production"
          "k8s.namespace.name": "{env.MY_K8_NAMESPACE_ENV_VARIABLE}"
```

For OpenTelemetry conventions for resources, see [Resource Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md).


### `buckets`

You can customize bucket boundaries for all generated histograms by setting `telemetry.exporters.metrics.common.buckets` in [`router.yaml`](/router/configuration/overview/#yaml-config-file). For example:

```yaml title="router.yaml"
telemetry:
  exporters:
    metrics:
      common:
        buckets:
          - 0.05
          - 0.10
          - 0.25
          - 0.50
          - 1.00
          - 2.50
          - 5.00
          - 10.00
          - 20.00
```

### `views`

OpenTelemetry views enable you to customize metrics behavior, including renaming metrics, overriding attributes, changing default buckets, or dropping metrics entirely.

#### Renaming metrics

You can rename metrics to match your organization's naming conventions or to align with existing monitoring infrastructure. This is particularly useful for customizing OTLP semantic convention metrics.

```yaml title="router.yaml"
telemetry:
  exporters:
    metrics:
      common:
        service_name: apollo-router
        views:
          - name: http.server.request.duration # Instrument name to rename
            rename: apollo.router.http.request.duration # New metric name

```

<Note>

Important naming considerations:

- OTLP exporters use the renamed metric name exactly as specified.
- Prometheus exporters automatically transform metric names:
  - Dots (`.`) are converted to underscores (`_`).
  - Unit suffixes are added (e.g., `_seconds`, `_bytes`).
  - For example, `apollo.router.http.duration` becomes `apollo_router_http_duration_seconds`.
- Apollo Studio metrics aren't affected by renaming and continue to use the original metric names.

</Note>

You can combine `rename` with other view properties:

```yaml title="router.yaml"
telemetry:
  exporters:
    metrics:
      common:
        views:
          - name: apollo.router.operations
            rename: custom.graphql.operations
            description: "Custom GraphQL operation metrics"
            aggregation:
              histogram:
                buckets: [0.1, 0.5, 1.0, 5.0, 10.0]
            allowed_attribute_keys:
              - graphql.operation.name
              - graphql.operation.type

```

#### Customizing metric attributes and buckets

You can override default attributes and buckets for specific metrics:

```yaml title="router.yaml"
telemetry:
  exporters:
    metrics:
      common:
        service_name: apollo-router
        views:
          - name: apollo_router_http_request_duration_seconds # Instrument name you want to edit. You can use wildcard in names. If you want to target all instruments just use '*'
            unit: "ms" # (Optional) override the unit
            description: "my new description of this metric" # (Optional) override the description
            aggregation: # (Optional)
              histogram:
                buckets: # Override default buckets configured for this histogram
                - 1
                - 2
                - 3
                - 4
                - 5
            allowed_attribute_keys: # (Optional) Keep only listed attributes on the metric
            - status

```

#### Dropping metrics

You can drop specific metrics if you don't want them sent to your APM:

```yaml title="router.yaml"
telemetry:
  exporters:
    metrics:
      common:
        service_name: apollo-router
        views:
          - name: apollo_router_http_request_duration_seconds # Instrument name you want to edit. You can use wildcard in names. If you want to target all instruments just use '*'
            aggregation: drop

```

## Metrics common reference

| Attribute           | Default                  | Description                                                                                                                      |
|---------------------|--------------------------|----------------------------------------------------------------------------------------------------------------------------------|
| `service_name`      | `unknown_service:router` | The OpenTelemetry service name.                                                                                                  |
| `service_namespace` |                          | The OpenTelemetry namespace.                                                                                                     |
| `resource`          |                          | The OpenTelemetry resource to attach to metrics.                                                                                 |
| `views`             |                          | Customizes metrics using OpenTelemetry views: rename metrics, override default buckets and attributes, or drop metrics entirely. |


## Related topics

* [Connecting OpenTelemetry traces to Prometheus](/technotes/TN0003-opentelemetry-traces-to-prometheus)
* [Sending router traces and metrics to APM tools using OpenTelemetry](/graphos/reference/router/telemetry/metrics-exporters/overview)
